package com.cszjzx.member.service;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cszjzx.member.dao.StageDao;
import com.cszjzx.member.dao.StageDaoImpl;
import com.cszjzx.member.po.Stage;

public class StageServiceImpl implements StageService {

	private StageDao stageDao = null;
	
	public StageServiceImpl(){
		try {
			stageDao = new StageDaoImpl();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public List<Stage> getStageList() {
		List<Stage> sList = null;
		
		try {
			sList = stageDao.findAll();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return sList;
	}

	@Override
	public Map<String, Integer> getStageAndValue() {
		Map<String, Integer> maplist = new HashMap<String, Integer>();
		try {
			List<Stage> sList = stageDao.findAll();
			for (int i = 0 ; i < sList.size() ; i ++) {
				maplist.put(sList.get(i).getName(), 0);
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return maplist;
	}

	@Override
	public boolean editStage(Stage s) {
		try {
			stageDao.update(s);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		return true;
	}

}
